package com.glsc.ngateway.opmanage.controller.deposit;

import com.glsc.ngateway.common.api.platform.resp.PlatformResponse;
import com.glsc.ngateway.common.base.domain.mysql.opmanagemain.deposit.DepositoryDayEndTrial;
import com.glsc.ngateway.common.base.domain.mysql.opmanagemain.deposit.DepositoryDayStartData;
import com.glsc.ngateway.opmanage.dto.DepositoryDto;
import com.glsc.ngateway.opmanage.dto.DepositoryStartDataExcelDto;
import com.glsc.ngateway.opmanage.service.deposit.DepositoryDayStartDataService;
import com.glsc.ngateway.opmanage.utils.report.ReportUploadContext;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 保证金如初数据导入
 */
@RestController
@RequestMapping("/api/depository/")
@Slf4j
public class DepositoryDayStartDataController {

    @Resource
    private DepositoryDayStartDataService depositoryDayStartDataService;

    /**
     * 保证金如初数据导入
     *
     * @return
     * @throws IOException
     */
    @PostMapping("/dayStartDate/import")
    @ApiOperation(value = "保证金如初数据导入", notes = "保证金如初数据导入")
    public PlatformResponse<?> outSystemImport(@RequestPart("file") MultipartFile file) throws IOException {
        ReportUploadContext<DepositoryStartDataExcelDto, String> context = depositoryDayStartDataService.dataImport(file);
        return context.isCheckPass() ? PlatformResponse.successData(context.getReadRes()) : PlatformResponse.failedMsg(String.join(",", context.getCheckRes()));
    }

    /**
     * 分页查询
     *
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("/dayStartData/page")
    public PlatformResponse<Page<DepositoryDayStartData>> page(@RequestBody DepositoryDto dto, HttpServletRequest request) {

        Map<String, Object> param = new HashMap<>();
        if (StringUtils.isNotBlank(dto.getEffectDate())) {
            param.put("LIKE_effectDate", dto.getEffectDate());
        }
        Page<DepositoryDayStartData> page = depositoryDayStartDataService.page(dto.getPageNo(), dto.getPageSize(), param);

        return PlatformResponse.successData(page);
    }


}
